<?php
namespace admin\action;

use herosphp\http\HttpRequest;
use herosphp\utils\AjaxResult;
use herosphp\bean\Beans;

/**--tmpl-use--**/

class AdPlaceAction extends CommonAction {

	protected $serviceBean="information.informationAdPlace.service";

	public function C_start()
	{
		parent::C_start();
	}

	public function add(HttpRequest $request) {
		location(url('/admin/adPlace/index'));
		parent::add($request);
		$this->assign("title", "添加广告位");
        $this->assign('bread', array('信息管理','广告位列表',$this->getTemplateVar('title')));
        $this->assign('breadUrl', array('javascript:;',url('admin/adPlace/index'),'javascript:;'));
	
	}
	public function edit(HttpRequest $request) {
		//location(url('/admin/adPlace/index'));
		parent::edit($request);
		$this->assign("title", "编辑广告位");
        $this->assign('bread', array('信息管理','广告位列表',$this->getTemplateVar('title')));
        $this->assign('breadUrl', array('javascript:;',url('admin/adPlace/index'),'javascript:;'));
	}
	public function index(HttpRequest $request) {
		$conditions = array();
		$this->assign('_table','广告位');
		$s_title = $request->getParameter('s_title');
		$this->assign('s_title',$s_title);
		if($s_title !== '' && $s_title!== NULL)$conditions['title'] = '%'.$s_title.'%';
		$s_summary = $request->getParameter('s_summary');
		$this->assign('s_summary',$s_summary);
		if($s_summary !== '' && $s_summary!== NULL)$conditions['summary'] = '%'.$s_summary.'%';
		$s_width = $request->getParameter('s_width');
		$this->assign('s_width',$s_width);
		if($s_width !== '' && $s_width!== NULL)$conditions['width'] = '%'.$s_width.'%';
		$s_height = $request->getParameter('s_height');
		$this->assign('s_height',$s_height);
		if($s_height !== '' && $s_height!== NULL)$conditions['height'] = '%'.$s_height.'%';
		$s_cate = $request->getParameter('s_cate');
		$this->assign('s_cate',$s_cate);
		if($s_cate !== '' && $s_cate!== NULL)$conditions['cate'] = '%'.$s_cate.'%';
		$s_default_type = $request->getParameter('s_default_type');
		echo $s_default_type;
		$this->assign('s_default_type',$s_default_type);
		if($s_default_type !== '' && $s_default_type!== NULL)$conditions['default_type'] = '%'.$s_default_type.'%';
		$s_default_content = $request->getParameter('s_default_content');
		$this->assign('s_default_content',$s_default_content);
		if($s_default_content !== '' && $s_default_content!== NULL)$conditions['default_content'] = '%'.$s_default_content.'%';
		$s_status = $request->getParameter('s_status');
		$this->assign('s_status',$s_status);
		if($s_status !== '' && $s_status!== NULL)$conditions['status'] = '%'.$s_status.'%';
		$s_manager_id = $request->getParameter('s_manager_id');
		$this->assign('s_manager_id',$s_manager_id);
		if($s_manager_id !== '' && $s_manager_id!== NULL)$conditions['manager_id'] = '%'.$s_manager_id.'%';
		$s_app_id = $request->getParameter('s_app_id');
		$this->assign('s_app_id',$s_app_id);
		if($s_app_id !== '' && $s_app_id!== NULL)$conditions['app_id'] = '%'.$s_app_id.'%';
		$this->assign('_filter',array('title','summary','width','height','cate','default_type','default_content','status','admin_manager_id','app_id'));
		$this->assign('_header',array('标题','描述','宽','高','打开方式','默认显示','默认显示的内容','打开方式','操纵人','AppId'));
		$this->setConditions($conditions);
	
		$pagesize = $request->getParameter('pagesize') ? $request->getParameter('pagesize') : $this->getPagesize();
		$order = $request->getParameter('order') ? $request->getParameter('order') : $this->getOrder();
		$order = str_replace('+' , " ",$order);
		$this->setPagesize($pagesize);
		$this->setOrder($order);
		$this->assign('order',$order);
		$this->assign('pagesize',$pagesize);

		$this->page = $request->getParameter('page', 'intval');
		if ( $this->page <=0 ) {
			$this->page = 1;
		}
		$service = Beans::get($this->getServiceBean());
		$total = $service->count($this->getConditions());
		$items = $service->getItems($this->getConditions(), $this->getFields(), $this->getOrder(),
				array($this->getPage(), $this->getPagesize()), $this->getGroup(), $this->getHaving());
		$this->assign('items',$items);
		$this->generatePageMenu($total);
		//parent::index($request);
		$this->assign("title", "广告位列表");
        $this->assign('bread', array('信息管理',$this->getTemplateVar('title')));
        $this->assign('breadUrl', array('javascript:;','javascript:;'));
		$this->setView(strtolower($request->getAction()) . '/index');
	}

	public function do_add(HttpRequest $request)
	{
		location(url('/admin/adPlace/index'));
		$data = $request->getParameter('data');
		$data['key'] = MD5($data['title']);
		$data['summary'] = $data['title'];
		$data['default_content'] = $data['title'];
		$request->addParameter('data',$data);
		parent::do_add($request);	
	}


	public function do_edit(HttpRequest $request){
		location(url('/admin/adPlace/index'));
		$data = $request->getParameter('data');
		$request->addParameter('data',$data);
		parent::do_edit($request);	
	}
}
